package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        Class cls = Class.forName("reflect.Person");

        Object obj = cls.newInstance();

        Method[] methods = cls.getDeclaredMethods();

        for (Method method:
             methods) {
            if(method.getParameterCount() == 0){
                System.out.println("自动调用：" + method.getName() + "()");
                method.setAccessible(true);
                method.invoke(obj);
            }
        }




    }
}
